package part11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.ListIterator;
import java.util.Random;

/**
 * @author wcj
 * @Date 2021/5/20 17:40
 * @Version 1.0
 */
public class Part118 {

    /**
     * listIterator是Iterator迭代器的子类，提供了仅用于List容器使用的迭代器，功能更加强大
     * 能双向遍历等等操作
     *
     * @param args
     */
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
        ListIterator<Integer> iterator = list.listIterator();
        while (iterator.hasNext()) {
            iterator.next();
            System.out.println(iterator.next() + "," + iterator.nextIndex() + "," + iterator.previous());
        }
        System.out.println();
        while (iterator.hasPrevious()) {
            System.out.println(iterator.previous());
        }
        System.out.println();
        System.out.println(list);
        iterator = list.listIterator(5);
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
            iterator.set(new Random(47).nextInt(10));
        }
        System.out.println(list);
    }
}
